<template>
  <div class="home">
    <el-form
      :model="ruleForm"
      status-icon
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="账号" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          type="password"
          v-model="ruleForm.password"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import { login } from "@/api/login/login";
export default {
  name: "Home",
  components: {
    HelloWorld,
  },
  data() {
    return {
      ruleForm: {
        name: "",
        passsword: "",
      },
    };
  },
  methods: {
    //遍历二叉树
    // fun(root) {
    //   if (root == null) {
    //     return false;
    //   }
    //   var left = root.left;
    //   if (left != null) {
    //     this.getInitData(left);
    //   }
    //   var right = root.right;
    //   if (right != null) {
    //     this.getInitData(right);
    //   }
    //   return root.val;
    // },

    submitForm() {
      // debugger;
      // let { name, password } = this.ruleForm;
      // let data = {
      //   id: 1,
      //   name: "li",
      // };
      // login(data).then((res) => {
      //   if (res.data.status == 0) {
      //     sessionStorage.setItem("name", name);
      //     sessionStorage.setItem("password", password);
      //     this.$router.push({
      //       path: "/home",
      //     });
      //   } else {
      //     alert("密码错误");
      //   }
      // });

      let { name, password } = this.ruleForm;
      if (name == 123 && password == 123) {
        sessionStorage.setItem("name", name);
        sessionStorage.setItem("password", password);
        this.$router.push({
          path: "/home",
        });
      }
    },
  },
  mounted() {
    //二叉树各个节点
    // var root = {
    //   left: {
    //     left: { val: 1 },
    //     right: {
    //       left: { val: 3 },
    //       right: { val: 5 },
    //       val: 9,
    //     },
    //     val: 6,
    //   },
    //   right: { val: 7 },
    //   val: 4,
    // };
    //  this.fun(root);
  },
};
</script>

<style scoped>
.home {
  text-align: center;
  padding: 398px;
}
</style>
